*dl 9-8-18
*Replication, Determinants of Writing Style on CCA, JLC.


local path="C:\docs\Informality" //modify this line to where data is stored.
use "`path'\bhl_jlc_18_data.dta",clear
//note that this dataset is a subset of a massive ds that combines various
//archived dss and original data. contact Daniel Lempert if interested in
//variables not included here (i.e., not used in analysis).



********************************************************************************
*Table 1. (Descriptives)

local judge_ivs __ccajudge __ideology __jrepub __apdem __nonwhite __jewish ///
__male __catholic __baivy __jdelite __graddeg __lawprof __jage __rexp ///
__fedpros __statepros __privatepractice i.__region 

local case_ivs __iss1-__iss5 __iss7-__iss9 i.year i.cir
local strat_ivs __j5dist __pmeddist __hmeddist __senmeddist __cirmeddist ///
__pmedhmeddist __pmedsenmeddist __pmedj5dist __pmedcirmeddist


qui reg __fkgl `case_ivs' `judge_ivs' `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0, robust 

foreach var of local judge_ivs{
summ `var' if e(sample)
}
********************************************************************************






********************************************************************************
*Table 2.

*illustrative regression--basic approach--fkgl.
local judge_ivs __ccajudge __ideology __jrepub __apdem __nonwhite __jewish ///
__male __catholic __baivy __jdelite __graddeg __lawprof __jage __rexp ///
__fedpros __statepros __privatepractice i.__region 

local case_ivs __iss1-__iss5 __iss7-__iss9 i.year i.cir
local strat_ivs __j5dist __pmeddist __hmeddist __senmeddist __cirmeddist ///
__pmedhmeddist __pmedsenmeddist __pmedj5dist __pmedcirmeddist


reg __fkgl `case_ivs' `judge_ivs' `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0, robust 
di `e(r2_a)'
est store mfull_all

reg __fkgl `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 & e(sample), robust 
di `e(r2_a)'
est store mstrat_all

reg __fkgl __iss1-__iss5 __iss7-__iss9 [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0  ///
& e(sample), robust
di `e(r2_a)' 
est store missue_all

reg __fkgl `case_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 & e(sample), robust 
di `e(r2_a)'
est store mcase_all

reg __fkgl `judge_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 & e(sample), robust 
di `e(r2_a)'
est store mjudge_all

*Table 2:
estout  mstrat_all mjudge_all missue_all mcase_all mfull_all, cells(b(star fmt(3)) ///
se(par fmt(2))) mlabels(STRAT JUDGE ISSUE CASE FULL ) legend stats(N bic r2_a) ///
starlevels(+ .1 * .05 ** .01 *** .001) drop(*circuit *year) 

********************************************************************************





********************************************************************************
*Table 3. ripe for strategy cases only

local judge_ivs __ccajudge __ideology __jrepub __apdem __nonwhite __jewish ///
__male __catholic __baivy __jdelite __graddeg __lawprof __jage __rexp ///
__fedpros __statepros __privatepractice i.__region

local case_ivs __iss1-__iss5 __iss7-__iss9 i.year i.cir
local strat_ivs __j5dist __pmeddist __hmeddist __senmeddist __cirmeddist ///
__pmedhmeddist __pmedsenmeddist __pmedj5dist __pmedcirmeddist


qui reg __fkgl `case_ivs' `judge_ivs' `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 ///
& (__binamicus==1 | __binintrev==1 | __bindissent==1) ,robust
est store mfull_lsalient //"loosely salient"

reg __fkgl __j5dist __cirmeddist [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0  ///
& (__binamicus==1 | __binintrev==1 | __bindissent==1) & e(sample) , robust
di `e(r2_a)'


reg __fkgl `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 ///
& (__binamicus==1 | __binintrev==1 | __bindissent==1) & e(sample), robust
di `e(r2_a)'
est store mstrat_lsalient

reg __fkgl __iss1-__iss5 __iss7-__iss9 [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 ///
& (__binamicus==1 | __binintrev==1 | __bindissent==1) & e(sample), robust
di `e(r2_a)' 
est store missue_lsalient

reg __fkgl `case_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0 ///
& (__binamicus==1 | __binintrev==1 | __bindissent==1) & e(sample), robust
di `e(r2_a)' 
est store mcase_lsalient


reg __fkgl `judge_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0  ///
& (__binamicus==1 | __binintrev==1 | __bindissent==1) &  e(sample), robust
di `e(r2_a)'
est store mjudge_lsalient


*Table 3:
estout mstrat_lsalient mjudge_lsalient missue_lsalient mcase_lsalient mfull_lsalient , cells(b(star fmt(3)) ///
se(par fmt(2))) mlabels(STRAT JUDGE ISSUE CASE FULL ) legend stats(N bic r2_a) ///
starlevels(+ .1 * .05 ** .01 *** .001) drop(*circuit *year)
********************************************************************************





*******************************************************************************
*Tables 4 and 5.


gen __aADJR2_textvar="" //name of var in question
gen __aADJR2_j=. //R2, judge attributes
gen __aADJR2_s=. //R2, strategic factors
gen __aADJR2_c=. //R2, case factors
gen __aADJR2_i=. //R2, case factors (Issue area only)
gen __aADJR2_cjs=. //R2, case+judge+strategic
gen __aN_cjs=. //N for (fullest) regression in question
gen __aF_cjs=. //F test for (fullest) regression in question (check for missing vals).




local judge_ivs __ccajudge __ideology __jrepub __apdem __nonwhite __jewish ///
__male __catholic __baivy __jdelite __graddeg __lawprof __jage __rexp ///
__fedpros __statepros __privatepractice i.__region

local case_ivs __iss1-__iss5 __iss7-__iss9 i.year i.cir
local issue_ivs __iss1-__iss5 __iss7-__iss9
local strat_ivs __j5dist __pmeddist __hmeddist __senmeddist __cirmeddist ///
__pmedhmeddist __pmedsenmeddist __pmedj5dist __pmedcirmeddist


*local vlist __fkgl __acrwords //vlist will be a (more comprehensive) varlist.


local i=1
local vlist  __ainformFactor_fullSample __complexFactor_fullSample ///
__fkgl __asvmIF __acrwords LI_wc - LI_otherp


quietly foreach v0 of varlist `vlist'{

replace __aADJR2_textvar="`v0'" in `i' 

reg `v0' `case_ivs' `judge_ivs' `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0, robust //omit labor;
replace __aADJR2_cjs=`e(r2_a)' in `i'
tempvar asamp
gen `asamp'=1 if e(sample)==1


reg `v0'  `judge_ivs' [pweight=__wt] ///
if `asamp'==1 , robust 
*ereturn list
replace __aADJR2_j=`e(r2_a)' in `i'

reg `v0'  `case_ivs' [pweight=__wt] ///
if `asamp'==1 , robust //omit labor;
replace __aADJR2_c=`e(r2_a)' in `i'

reg `v0'  `issue_ivs' [pweight=__wt] ///
if `asamp'==1 , robust 
replace __aADJR2_i=`e(r2_a)' in `i'

reg `v0'  `strat_ivs' [pweight=__wt] ///
if `asamp'==1 , robust 
replace __aADJR2_s=`e(r2_a)' in `i'

reg `v0' `case_ivs' `judge_ivs'  `strat_ivs' [pweight=__wt] ///
if `asamp'==1 ,  robust //omit labor;
replace __aADJR2_cjs=`e(r2_a)' in `i'


replace __aN_cjs=`e(N)' in `i'
replace __aF_cjs=`e(F)' in `i'


local i=`i'+1
noisily di `i'
}

*Table 4 and 5: 
*(in order, judge vars, case vars, strategic vars, and case vars--issue area only)
summ __aADJR2_j __aADJR2_c __aADJR2_s __aADJR2_i, det

********************************************************************************

*to look at R2 values for individual text vars:
list __aADJR2_textvar __aADJR2_j __aADJR2_c __aADJR2_i __aADJR2_s  in 1/98










********************************************************************************
*Table 6:

gen __ADJR2_textvar="" //name of var in question
gen __ADJR2_j=. //R2, judge attributes
gen __ADJR2_s=. //R2, strategic factors
gen __ADJR2_c=. //R2, case factors
gen __ADJR2_e=. //R2, extra opinion text attribute
gen __ADJR2_cjs=. //R2, case+judge+strategic
gen __ADJR2_cejs=. //R2, case+extra op text att+judge+strategic (full model)
gen __ADJR2_js=. //...
gen __ADJR2_ec=. //...
gen __N_cejs=. //N for (fullest) regression in question
gen __F_cejs=. //F test for (fullest) regression in question (check for missing vals).


gen __eop_tscore=. // (b/se) for extra opinion text var in full model.



tempvar tv

local judge_ivs __ccajudge __ideology __jrepub __apdem __nonwhite __jewish ///
__male __catholic __baivy __jdelite __graddeg __lawprof __jage __rexp ///
__fedpros __statepros i.__region __privatepractice
local case_ivs __iss1-__iss5 __iss7-__iss9 i.year i.cir
local strat_ivs __j5dist __pmeddist __hmeddist __senmeddist __cirmeddist ///
 __pmedcirmeddist __pmedhmeddist __pmedsenmeddist __pmedj5dist


*local vlist __fkgl __acrwords //vlist will be a (more comprehensive) varlist.


local i=1
local vlist  __ainformFactor_fullSample __complexFactor_fullSample ///
__fkgl __asvmIF __acrwords LI_wc - LI_otherp


quietly foreach v0 of varlist `vlist'{

replace __ADJR2_textvar="`v0'" in `i' 
replace __ADJR2_textvar="__ainformFactor_fullSample" in 1 


bysort casenum: egen `tv'=mean(`v0') ///
if __jno != 1 & __curiam == 0 & __filesize > 1500 & __is > 0 //i.e., if obs is not maj op.
bysort casenum: egen __eop_`v0'=mode(`tv')  //replace missing values w/ mean if mean!=.
drop `tv'
//thus __eop_`v0' is mean of textual attribute among extra opinions.


reg `v0' __eop_`v0' `case_ivs' `judge_ivs' `strat_ivs' [pweight=__wt] ///
if __curiam==0 & __jno==1 & __filesize > 1500 & __is > 0, robust //omit labor;
replace __ADJR2_cejs=`e(r2_a)' in `i'
replace __eop_tscore=_b[__eop_`v0']/_se[__eop_`v0'] in `i'
tempvar samp
gen `samp'=1 if e(sample)==1

replace __N_cejs=`e(N)' in `i'
replace __F_cejs=`e(F)' in `i'



reg `v0'  `judge_ivs' [pweight=__wt] ///
if `samp'==1 , robust //omit labor;
*ereturn list
replace __ADJR2_j=`e(r2_a)' in `i'

reg `v0'  `case_ivs' [pweight=__wt] ///
if `samp'==1 , robust //omit labor;
replace __ADJR2_c=`e(r2_a)' in `i'

reg `v0'  `strat_ivs' [pweight=__wt] ///
if `samp'==1 , robust //omit labor;
replace __ADJR2_s=`e(r2_a)' in `i'

reg `v0' `case_ivs' `judge_ivs'  `strat_ivs' [pweight=__wt] ///
if `samp'==1 ,  robust //omit labor;
replace __ADJR2_cjs=`e(r2_a)' in `i'

reg `v0' __eop_`v0'  [pweight=__wt] ///
if `samp'==1  , robust //omit labor;
replace __ADJR2_e=`e(r2_a)' in `i'

replace __ADJR2_ec=__ADJR2_e+__ADJR2_c in `i'
replace __ADJR2_js=__ADJR2_j+__ADJR2_s in `i'

drop __eop_`v0'

local i=`i'+1
noisily di `i'
}

*Table 6:
*(in order, judge vars, case vars, strategic vars, text feature in separate op)
summ __ADJR2_j __ADJR2_c __ADJR2_s __ADJR2_e, det

*******************************************************************************



*to look at values for individual text vars
list __ADJR2_textvar __ADJR2_j __ADJR2_c __ADJR2_s __ADJR2_e in 1/98
*list __aADJR2_textvar __aADJR2_j __aADJR2_c __aADJR2_i __aADJR2_s  if __aADJR2_textv !=""
